//
//  PublicCourseDetails.m
//  Courses
//
//  Created by xxx on 15/1/11.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "PublicCourseDetails.h"

#import "PublicCourse.h"

#import "Request.h"

@implementation PublicCourseDetails

//pStr *courseId;
//pStr *courseName;
//pStr *courseDescription;
//pStr *courseSerialId;
//pStr *courseSerialName;
//pStr *teacherId;
//pStr *teacherName;
//pStr *teacherTitle;
//pStr *teacherHeadPhotoUrl;
//pStr *teacherDescShort;
//pStr *favoritesNum;
//pStr *courseViewNum;
//pNS NSMutableArray *relatedCourses;

- (id)initWithJsonDict:(NSDictionary *)jsonDict
{
    if (self = [super init])
    {
        self.courseId = jsonDict[@"courseId"];
        self.courseName = jsonDict[@"courseName"];
        self.courseDescription = jsonDict[@"courseDescription"];
        self.courseSerialId = jsonDict[@"courseSerialId"];
        self.courseSerialName = jsonDict[@"courseSerialName"];
        self.teacherId = jsonDict[@"teacherId"];
        self.teacherName = jsonDict[@"teacherName"];
        self.teacherTitle = jsonDict[@"teacherTitle"];
        self.teacherHeadPhotoUrl = jsonDict[@"teacherHeadPhotoUrl"];
        self.teacherDescShort = jsonDict[@"teacherDescShort"];
        self.favoritesNum = jsonDict[@"favoritesNum"];
        self.courseViewNum = jsonDict[@"courseViewNum"];
        
        self.relatedCourses = [[NSMutableArray alloc] init];
        for (id dict in jsonDict[@"related"])
        {
            if ([dict isKindOfClass:[NSDictionary class]])
            {
                PublicCourse *course = [[PublicCourse alloc] initWithJsonDict:dict];
                [self.relatedCourses addObject:course];
            }
        }
    }
    return self;
}

+ (PublicCourseDetails *)courseDetailsByCourseId:(NSString *)courseId
{
    Request *request = [Request requestWithName:@"get_open_course_detail"];
    request.body[@"courseId"] = courseId;
    Response *response = [request response];
    
    PublicCourseDetails *details = nil;
    
    if (response.result)
    {
        details = [[self alloc] initWithJsonDict:response.content[@"courses"]];
    }
    
    return details;
}

@end
